//获取应用实例
const app = getApp();

var memberUtil = require('../../../utils/memberUtil');
Page({
  data: {
    autoplay: true,
    interval: 3000,
    duration: 1000,
    swiperCurrent: 0,
    selectCurrent: 0,
    activeCategoryId: 0,
    goodADs: [{
      "id": "4",//康养系列
      "pic": app.globalData.baseImageUrl+"/images/b_01.png"
    },
    {
      "id": "3",//壳好食品 季节产品
      "pic": app.globalData.baseImageUrl+"/images/b_02.png"
    },
      {
        "id": "2",//洗化用品
        "pic": app.globalData.baseImageUrl+"/images/b_03.png"
      },

    {
      "id": "6",//壳好用品
      "pic": app.globalData.baseImageUrl+"/images/b_04.png"
    },
    {
      "id": "5",//睡眠系列 大宗商品
      "pic": app.globalData.baseImageUrl+"/images/b_05.png"
      },
      {
        "id": "belongto",//积分专区
        "pic": app.globalData.baseImageUrl+"/images/b_06.png"
      }],
    banners: [],
    videoTopThreeGoods: null,
    searchInput: '',
    imagesUrl: app.globalData.baseImageUrl,
    serverImageUrl:app.globalData.baseUrl
  },
  //轮播图切换
  swiperchange: function (e) {
    this.setData({
      swiperCurrent: e.detail.current
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  //页面初始化加载
  onLoad: function (e) {
    var that = this;
    that.setData({
      userInfo:wx.getStorageSync("loginUserInfo").userInfo==undefined?"":wx.getStorageSync("loginUserInfo").userInfo
    })
    memberUtil.shareDL(app,e,"1",that);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this;
//获取banner
    that.getBanner();
//获取热门推荐列表
    that.getremenliebiao();
    that.goodsHotThreeList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
  //获取banner图
  getBanner:function(){
    var that = this;
    wx.showLoading({
      title: '加载中'
    })
    wx.request({
      url: app.globalData.baseUrl + '/index/banner/getThreeIndexBannerList',
      data: {},
      method: 'POST',
      success: function (re) {
        wx.hideLoading();
        that.setData({
          banners:re.data
        })
      }, fail: function (re) {
        wx.hideLoading();
        wx.showModal({
          title: '提示',
          content: '您的网络不给力哦！'
        })
      }
    });
  },

  //搜索处理方法
showInput: function () {
  wx.showLoading({
    title: '加载中',
    mask: true
  })
    //跳转到另一个页面
  wx.navigateTo({
    url: '/pages/shop/search'
  })
  wx.hideLoading();
  },

  //banner下面六个个广告详情页跳转
  toBannerADDetailsTap: function (e) {
    wx.showLoading({
      title: '数据加载中',
      mask: true
    })
    var tid = e.currentTarget.dataset.id;
    if(tid!=0){
      wx.navigateTo({
        url: "/pages/shop/shopList?aType=1&tid=" +tid
    })
    }
    wx.hideLoading();

  },

  //热门推荐详情页跳转
  toReMenXiangQingDetailsTap: function (e) {
    wx.navigateTo({
     url: "/pages/shop/shopDt?goodsId=" + e.currentTarget.dataset.id
    })
  },

  //视频专区上面三个产品
  goodsHotThreeList: function (id) {
    var that = this;
    wx.showLoading({
      title: '数据加载中',
      mask: true
    })
    var categoryIdJson = { categoryId:5}
    wx.request({
      url: app.globalData.baseUrl + "/goods/findThreeGoodsListByCategoryId",
      data: JSON.stringify(categoryIdJson),
      header: app.globalData.headerPost,
      method: 'POST',
      success: function (e) {
          that.setData({
            videoTopThreeGoods:e.data
          })
      },
      fail: function (e) {
        wx.showModal({
          title: "通知",
          content: "系统开小差了",
          showCancel: false,
          confirmText: "确定"
        })
      }
    })
  },

  //获取热门推荐列表
  getremenliebiao:function(){
    var that = this;
    wx.showLoading({
      title: '加载中'
    })
    wx.request({
      url: app.globalData.baseUrl + '/goods/findPopularRecommendationGoodsList',
      data: {},
      method: 'GET',
      success: function (re) {
        wx.hideLoading();
        if (re.data.length>0){
          that.setData({
            hotTuiJians:re.data
          })
        }else{
          that.setData({
            hotTuiJians: null
          })
          //启用默认图片
        }
      }, fail: function (re) {
        wx.hideLoading();
        wx.showModal({
          title: '提示',
          content: '系统开小差了'
        })
      }
    });
  },
  //二维码展示
  showScene:function(){
    wx.navigateTo({
      url: '/pages/shop/qrscene'
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    return{
      title: '我的二维码',
      path: "/pages/tabBar/shop/index?parentId=" + app.globalData.loginUserInfo.userInfo.id +"&enterType=0",
      imageUrl:app.globalData.loginUserInfo.erweimaUrl
    }
  }
})
